<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
{insert name="module_cssjs" css="core.css" js="jquery.min.js;top.js"}
</head>
{literal}
<script type="text/javascript">
$(document).ready(function() {

$('[name="isMenu"]').click(function() {
	if($(this).val() == 1) $('#controller').show();
	else $('#controller').hide().val('');
});
	
$('[name="add-form"]').submit(function() {
	var name = $('input[name="name"]').val();
	if(!name) {
		alert('请输入节点名称'); return false;
	}
	var target = $('input[name="target"]').val();
	if(!target) {
		alert('请输入节点标志'); return false;
	}
	var gid = $('select[name="gid"]').val();
	if(!gid) {
		alert('请选择节点分组'); return false;
	}
	var controller = $('input[name="controller"]').val();
	var isMenu = $('[name="isMenu"]:checked').val();
	if(!controller && isMenu == 1) {
		alert('请输入控制器'); return false;
	}
	var params = $('[name="add-form"]').serialize();
	$.post('/rbac/node/add.json', params, function(dt) {
		if(dt.status) {
			alert(dt.message);
		} else {
			window.location.href = '/rbac/node/';
		}
	}, 'json')
	return false;
});

$('[name="edit-form"]').submit(function() {
	var nodeId = $('input[name="nodeId"]').val();
	if(!nodeId) {
		alert('未知节点'); return false;
	}
	var name = $('input[name="name"]').val();
	if(!name) {
		alert('请输入节点名称'); return false;
	}
	var target = $('input[name="target"]').val();
	if(!target) {
		alert('请输入节点标志'); return false;
	}
	var gid = $('select[name="gid"]').val();
	if(!gid) {
		alert('请选择节点分组'); return false;
	}
	var controller = $('input[name="controller"]').val();
	var isMenu = $('[name="isMenu"]:checked').val();
	if(!controller && isMenu == 1) {
		alert('请输入控制器'); return false;
	}
	var params = $('[name="edit-form"]').serialize();
	$.post('/rbac/node/edit.json', params, function(dt) {
		if(dt.status) {
			alert(dt.message);
		} else {
			window.location.href = '/rbac/node/';
		}
	}, 'json')
	return false;
});
})
</script>
{/literal}
<body>
<h3 class="label">
	{if $act == 'edit'}
	<strong class="on"><span>编辑节点</span></strong>
	<span class="refresh"><a href="javascript:history.go(-1);">返回</a></span>
	{else}
	<strong><span><a href="/rbac/node/">所有节点</a></span></strong>
	<strong class="on"><span>添加节点</span></strong>
	{/if}
	<span class="refresh"><a href="">刷新</a></span>
</h3>
<div class="table">
	<form {if $act == 'edit'}name="edit-form"{else}name="add-form"{/if} action="post">
	{if $act == 'edit'}<input name="nodeId" type="hidden" value="{$info.node_id}" />{/if}
	<table class="TB-form">
		<tr>
			<td width="70">节点名称：</td>
			<td width="1200"><input class="input" name="name" value="{$info.name}" /></td>
		</tr>
		<tr>
			<td>节点标识：</td>
			<td><input class="input" name="target" value="{$info.target}" /></td>
		</tr>
		<tr>
			<td>菜&nbsp;&nbsp;&nbsp;&nbsp;单：</td>
			<td><input type="radio" name="isMenu" value="1" {if $info.is_menu}checked="checked"{/if} /> 是<input type="radio" name="isMenu" value="0" {if !$info.is_menu}checked="checked"{/if} /> 否</td>
		</tr>
		<tr id="controller" {if !$info.is_menu}class="hidden"{/if}>
			<td>控&nbsp;制&nbsp;器：</td>
			<td><input class="input" name="controller" value="{$info.controller}" /></td>
		</tr>
		<tr>
			<td>所&nbsp;属&nbsp;组：</td>
			<td><select class="select" name="gid">
				<option value="0">请选择分组</option>
				{foreach key=key item=item from=$groups}
				{if $item.sub}
				<optgroup label="{$item.name}">
				{foreach key=k item=i from=$item.sub}
					<option value="{$k}" {if $info.gid == $k}selected="selected"{/if}>{$i}</option>
				{/foreach}
				</optgroup>
				{/if}
				{/foreach}
				</select></td>
		</tr>
	</table>
	<div class="btn-box">
		<span class="btn-indent"><input class="btn" type="submit" value="保&nbsp;&nbsp;存" /></span>
		<span class="btn-indent"><input class="btn" type="reset" value="重&nbsp;&nbsp;置" /></span>
	</div>
	</form>
</div>

</body>
</html>